/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tree;

import java.util.List;

/**
 *
 * @author Ej-Dý
 */
public class FunTeloTree extends Tree {

    public List<VlastniProgramTree> vp;
    public VyrazTree ret;
    private String name;
    private ArgumentTree arg;
    private Type type;

     private int stackDepth;


    public FunTeloTree(Position start, Position end,List<VlastniProgramTree> vp, VyrazTree ret,String name, ArgumentTree arg,Type type){
        super(start,end);
        this.vp=vp;
        this.ret=ret;
        this.name=name;
        this.arg=arg;
        this.type=type;

    }

    public List<VlastniProgramTree> getBody(){
        return vp;
    }

     public VyrazTree getReturn(){
        return ret;
    }

     public int getStackDepth() {
        return stackDepth;
    }

    public void setStackDepth(int stackDepth) {
        this.stackDepth = stackDepth;
    }

    @Override
    public void accept(TreeVisitor visitor) {
        visitor.visitFunTelo(this);
    }

    @Override
    public void generate(Context ctx) {
        ctx.println("method "+name+"()");
                       
        ctx.println("stack "+stackDepth);
        ctx.println("locals "+arg.getPocet());
        
        for(VlastniProgramTree vpt: vp){
        vpt.generate(ctx);
        }
        ret.generate(ctx);
        if(type==Type.INTEGER){
            ctx.println("ireturn");
        }else{
            ctx.println("dreturn");
        }
        ctx.println("end");
        ctx.println("");

        
    }
    @Override
    public String toString(){
        return String.format("Argument %s: [%s,%s]", super.toString(), vp, ret);
    }
}
